package com.cdd.index.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdd.index.mapper.HeadNavMapper;
import com.cdd.index.service.IHeadNavService;
import com.cdd.index.vo.HeadNavVo;
import com.common.entity.HeadNav;
import com.common.entity.Role;
import com.common.untils.CommonResult;
import com.common.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzl
 * @since 2022-09-02
 */
@Service
public class HeadNavServiceImpl extends ServiceImpl<HeadNavMapper, HeadNav> implements IHeadNavService {

    @Autowired
    private HeadNavMapper headNavMapper;
    @Override
    public CommonResult selectAll(Integer currentPage,Integer pageSize,HeadNav headNav) {
        Page<HeadNav> page = new Page<>(currentPage,pageSize);
        QueryWrapper<HeadNav> wrapper =new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        if (StringUtils.hasText(headNav.getHeadName())){
            wrapper.like("head_name",headNav.getHeadName());
        }
        if (headNav.getIsDiable()!=null){
            wrapper.eq("is_diable",headNav.getIsDiable());
        }
        Page<HeadNav> headNavPage = headNavMapper.selectPage(page, wrapper);
        return new CommonResult(2000,"查询成功",headNavPage);
    }

    @Override
    public CommonResult headNavAdd(HeadNav ruleForm) {
        ruleForm.setIsDelete("0");
        ruleForm.setIsDiable("0");
        headNavMapper.insert(ruleForm);
        return new CommonResult(2000,"添加成功",null);
    }

    @Override
    public CommonResult deleteHead(Integer headId) {
        getBaseMapper().deleteById(headId);
        return new CommonResult(2000,"删除成功",null);
    }

    @Override
    public CommonResult update(HeadNav headNav) {
        headNavMapper.updateById(headNav);
        return new CommonResult(2000,"修改成功",null);
    }

    @Override
    public CommonResult updateStatus(Integer headId, String isDiable) {
                HeadNav headNav = new HeadNav();
                headNav.setHeadId(headId);
                headNav.setIsDiable(isDiable);
                int updateStatus = headNavMapper.updateById(headNav);
                return new CommonResult(2000,"修改状态成功",null);
    }

    @Override
    public CommonResult findAll() {
        QueryWrapper<HeadNav> wrapper = new QueryWrapper<>();
        wrapper.eq("is_diable",0);
        wrapper.eq("is_delete",0);
        List<HeadNav> headNavList = headNavMapper.selectList(wrapper);
        return new CommonResult(2000,"查询成功",headNavList);
    }
}
